// middleware/logger.go
package middleware

import (
    "time"
    "yunpan/logger"
    "github.com/gin-gonic/gin"
)

func Logger() gin.HandlerFunc {
    return func(c *gin.Context) {
        start := time.Now()
        path := c.Request.URL.Path
        method := c.Request.Method

        // 处理请求
        c.Next()

        // 记录API日志
        latency := time.Since(start)
        statusCode := c.Writer.Status()
        logger.LogAPI(method, path, statusCode, latency)
    }
}